#!/bin/bash


# using sed command 'w' to write the current pattern space to a file. 
# by defualt, pattern space will be printed to stdout after wrote to file.

# the operation is identical to print pattern space command 

# - write all content from source to destination
sed 'w test_output.txt' ./test_employee.txt

# - write only 2rd line to output file
sed '2 w test_output.txt' ./test_employee.txt # this write will clear original content of output file

# - write lines 1 though 4
sed -n '1,4 w test_output.txt' ./test_employee.txt

# - write lines matching the pattern
sed -n '/Raj/ w test_output.txt' ./test_employee.txt



# 
# clear test files 
if [ -f test_output.txt ]; then 
    echo "[shell] clearing test file.."
    rm test_output.txt
fi
